<?php include("helper/DBOperation.php");
$dbObj = new DBOperation();

include("helper/check_user_login.php");
checkUserIsLogin();

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name = "viewport" content = "width = device-width">

<meta name="apple-mobile-web-app-capable" content="yes" />

<title>HBMS - Email Log</title>
<link href="HBMS_css.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
// Mobile Safari in standalone mode
if(("standalone" in window.navigator) && window.navigator.standalone){

// If you want to prevent remote links in standalone web apps opening Mobile Safari, change 'remotes' to true
var noddy, remotes = false;

document.addEventListener('click', function(event) {

noddy = event.target;

// Bubble up until we hit link or top HTML element. Warning: BODY element is not compulsory so better to stop on HTML
while(noddy.nodeName !== "A" && noddy.nodeName !== "HTML") {
noddy = noddy.parentNode;
}

if('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes)) {
event.preventDefault();
document.location.href = noddy.href;
}

},false);
}

</script>


</head>

<body>

<div id="email_log_main">
	<div class="unit_a_content">
    
    	<div class="unit_a_top_row">
        	<div class="unit_a_cemusa_img"></div>
		<?php if($cookie['userslog']['is_admin']==1){ ?>
				<a href="admin/user_listing.php" style="text-decoration:none;color:white;"><img src="images/person.png" width="20px" height="20px" title="Add User"/></a>
			<?php }?>
            <div class="unita_top_text_part">
            	<div class="unita_top_txt1"><span>logged in as:</span><?=$cookie['userslog']['display_name']?></div>
                <div class="unita_top_txt1"><span>last update:</span> 
                <?php if($lastLogUpdateTime = $dbObj->lastUpdatedLogTime()) { echo $lastLogUpdateTime; } else { echo "00:00:00"; } ?>
                </div>
            </div>
        </div>
        
        
        <div class="component_cpu_middle_content">
        	
            <div id="scrolled" class="email_log_middle_content">
            	<div class="email_log_middle_top">Email log for CEMUSA@showandtell.com</div>
                <div class="email_log_middle_txt">
                	<div class="email_log_middle_txt">
			<?php
			/*$emails = $dbObj->getRecords("tbl_emails", "", "", "", "");
			//$con = mysql_connect("localhost","showandt_tphbm","gohbm");
			if (!$con)
			  {
			  die('Could not connect: ' . mysql_error());
			  }
			
			mysql_select_db("showandt_HBM", $con);
			*/
			$emails = mysql_query("SELECT * FROM tbl_emails ORDER BY id DESC");
			//mysql_close($con);
			//print_r($emails);exit;
			if(mysql_num_rows($emails)>0) {
				
				/* for every email... */
				while($email=mysql_fetch_assoc($emails)) {
			/*		$allEmail[] = $email;
				}
				$allEmail = array_reverse($allEmail);
				foreach($allEmail as $email) {*/
			?>
                    	<!-- email start -->
                        <div class="email_middle_mail1">
                        	<p><span>From:</span> &nbsp;&nbsp;&nbsp;<?php echo $email['from']; ?></p>
                            <p><span>Subject:</span><?php echo $email['subject']; ?></p>
							<p><span>Date:</span> &nbsp;&nbsp;&nbsp; <?php echo date("F d,Y H:i T",strtotime($email['date'])); ?></p>
                            
                            <div class="email_middle_mail_line"></div>
							<p><?php echo $email['body']; ?></p>
                            <?php if (strlen($email['attach'])>0){ ?>
                            <br />
							<img src="http://www.thetigerparty.com/Email_Test/images/<?php echo $email['attach'];?>" width="100%" />	
							<?php }	?>
                            
                         </div>
			<?php
				}
			}else{
				echo '<div class="email_middle_mail1">Sorry, Your inbox is empty.</div>';
			}
			/* close the connection */
			
			?>
			<!-- email end -->
                    </div>
                </div>
            </div>
            
        </div>
         <script type="text/javascript" src="js/touchscroll.js"></script>
        <div class="unita_showtell_row">
        	<div class="unita_showtell_img"></div>
        </div>
        
        <div class="unita_bottm_menu">
        	<?php include("footer.php");?>
        </div>
        
        
    </div>
</div>


</body>
</html>
